﻿/* 
 *	Copyright (C) 2010- ZWaveApi
 *	http://ZWaveApi.net
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 3, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/lesser.html
 *
 */

using System;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using System.Windows.Media.Imaging;
using ZWaveApi.ZWaveApiServiceReference;

namespace ZWaveApi.Controls
{
    public partial class ctlSwitchBinary : ctlGeneric
    {
        public ctlSwitchBinary()
        {
            InitializeComponent();
        }
        private void btnSwitchBinary_Click(object sender, RoutedEventArgs e)
        {
            CommandClassClient commandClassClient = new CommandClassClient();

            commandClassClient.PutCommandClassCompleted += delegate(object sender1, AsyncCompletedEventArgs e1)
            {
            };

            SwitchBinary sw = (SwitchBinary)DataContext;

            commandClassClient.PutCommandClassAsync(sw.NodeId, sw);
        }

        public override void GetState(byte nodeId, CommandClass commandClass)
        {
            CommandClassClient commandClassClient = new CommandClassClient();

            commandClassClient.GetCommandClassCompleted += delegate(object sender1, GetCommandClassCompletedEventArgs e1)
            {
                
                if (((SwitchBinary)e1.Result).State == BinaryStatus.Off)
                {
                    imgSwitchBinary.Source = new BitmapImage(new Uri("../Images/LampeOff.JPG", UriKind.Relative));

                    imgSwitchBinary.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    imgSwitchBinary.Source = new BitmapImage(new Uri("../Images/LampeOn.JPG", UriKind.Relative));

                    imgSwitchBinary.Visibility = System.Windows.Visibility.Visible;
                }
            };

            commandClassClient.GetCommandClassAsync(nodeId: nodeId, commandClass: commandClass);
        }
    }
}
